<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class JinpaiRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()){
            case 'POST':
                return [
                    //
                    'good_id' => 'required|exists:goods,id',
                    'good_name' => 'required|exists:goods,goods_name',
                    'cate_id' => 'required|exists:good_categories,id',
                    'cate_name' => 'required|exists:good_categories,cname',
                    'min_price' =>  'required|numeric',
                    'is_hot' => 'boolean'
                ];
                break;
            case 'PUT':
                return [
                    //
                    'good_id' => 'exists:goods,id',
                    'cate_id' => 'exists:goods,id',
                    'good_name' => 'exists:goods,goods_name',
                    'min_price' =>  'numeric',
                    'cate_name' => 'exists:good_categories,cname',
                    'is_hot' => 'boolean'
                    ];
                break;
        };

    }
}
